home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / timeoday.c < prev    next >
C/C++ Source or Header  |  1991-11-10  |  902b  |  55 lines

  1. /* BSDish gettimeofday() and settimeofday() calls */
  2. /* also ftime(), which seems to be similar to gettimeofday() */
  3.  
  4. #include <types.h>
  5. #include <time.h>
  6. #include <unistd.h>
  7. #include <sys/timeb.h>
  8.  
  9. extern int _dst;    /* in time.c */
  10. extern long _timezone;    /* in localtim.c */
  11.  
  12. int
  13. gettimeofday( tv, tzp )
  14.     struct timeval *tv;
  15.     struct timezone *tzp;
  16. {
  17.     struct timeb tp;
  18.     int r;
  19.  
  20.     r = ftime(&tp);
  21.     if (r) return r;
  22.  
  23.     if (tv) {
  24.         tv->tv_sec = tp.time;
  25.         tv->tv_usec = 0;
  26.     }
  27.     if (tzp) {
  28.         tzp->tz_minuteswest = tp.timezone;
  29.         tzp->tz_dsttime = tp.dstflag;
  30.     }
  31.     return 0;
  32. }
  33.  
  34. int
  35. settimeofday( tv, tzp )
  36.     struct timeval *tv;
  37.     struct timezone *tzp;
  38. {
  39.     return stime(&tv->tv_sec);
  40. }
  41.  
  42. int
  43. ftime(tp)
  44.     struct timeb *tp;
  45. {
  46.     long t = time((time_t *)0);
  47.  
  48.     tp->time = t;
  49.     tp->millitm = 0;
  50.     tp->timezone = _timezone / 60;
  51.     tp->dstflag = (_dst) ? 1 : 0;
  52.  
  53.     return 0;
  54. }
  55.